package com.jiniutech.enterprise.controller;

import com.jiniutech.enterprise.component.BaseConfig;
import com.jiniutech.enterprise.component.EnterpriseConfig;
import com.jiniutech.enterprise.util.aes.AesException;
import com.jiniutech.enterprise.util.aes.WXBizMsgCrypt;
import lombok.extern.slf4j.Slf4j;

@Slf4j
public class ParentController {
    protected String getCheckResult(String msgSignature,
                                  Integer timestamp,
                                  String nonce,
                                  String echoStr,
                                  BaseConfig config){
        log.info("msg_signature:" + msgSignature);
        log.info("timestamp:" + timestamp.toString());
        log.info("nonce:" + nonce);
        log.info("echostr:" + echoStr);

        String sToken = config.getToken();
        String sCorpID = config.getCropId();
        String sEncodingAESKey = config.getEncodingAESKey();

        try {
            WXBizMsgCrypt wxcpt = new WXBizMsgCrypt(sToken, sEncodingAESKey, sCorpID);

            String sEchoStr = wxcpt.VerifyURL(msgSignature, timestamp.toString(),
                    nonce, echoStr);
            System.out.println("verifyurl echostr: " + sEchoStr);
            return sEchoStr;
        } catch (AesException e) {
            e.printStackTrace();
        }
        return null;
    }
}
